/*Player command*/

--Player settings handler
function  db_send_player_settings( player, command, args )
	if ( args[1] == "3141" ) then
		print( "Player " .. player:Nick( ) .. " has requested " .. args[2] .. " and " .. args[3] .. " as their playermodels." )
		print( player:Nick( ) .. "'s command is valid, the proper code was given." )
		player.PrefCombModel = args[3]
		player.PrefLambModel = args[2]
		Save_Player_Data( player )
	else
		print( player:Nick( ) .. "'s command failed, incorrect code was given. Kicking player." )
		player:Kick( "Trying to break the server." )
	end
end

concommand.Add( "db_send_player_settings", db_send_player_settings )

--This allows an admin or owner to restart the current map
function Restart( player, command, args )
	if ( args[1] == "3141" ) then
		print( player:Nick( ) .. " reset the round." )
		Save_All_Player_Data( )
		RunConsoleCommand( "changegamemode", game.GetMap( ), "Dodgeball" )
	else
		print( player:Nick( ) .. " tried to run the changelevel concommand." )
	end
end

concommand.Add( "db_reset_map", Restart )

--This allows players to place a vote on a particular map
function PlayerVoteMap( player, command, args )
	if ( args[1] == "3141" ) then
		local mapvote = tonumber( args[2] )
		print( player:Nick( ) .. " placed a vote for " .. GAMEMODE.maps[mapvote] )
		GAMEMODE.mapVotes[mapvote] = GAMEMODE.mapVotes[mapvote] + 1
		//Be sure to update the players of the vote
		umsg.Start( "player_voted")
			umsg.String( string.Implode(",", GAMEMODE.mapVotes) )
		umsg.End( )
		player:PrintMessage( HUD_PRINTTALK, "You placed a vote for " .. GAMEMODE.maps[mapvote] )
	else
		print( player:Nick( ) .. " tried to vote for a map incorrectly.")
	end
end

concommand.Add( "db_map_place_vote", PlayerVoteMap )

--This allows a player to remove their vote from a map
function PlayerRemoveVote( player, command, args )
	if ( args[1] == "3141" ) then
		local map = tonumber( args[2] )
		print( player:Nick( ) .. "removed their vote for " .. GAMEMODE.maps[map] )
		GAMEMODE.mapVotes[map] = GAMEMODE.mapVotes[map] - 1
		umsg.Start( "player_voted")
			umsg.String( string.Implode(",", GAMEMODE.mapVotes) )
		umsg.End( )
	else
	
	end
end

concommand.Add( "db_map_remove_vote", PlayerRemoveVote)

function PlayerRequestUpdate( player, command, args )
	umsg.Start( "player_voted", player)
		umsg.String( string.Implode(",", GAMEMODE.mapVotes) )
	umsg.End( )	
end

concommand.Add( "db_map_update", PlayerRequestUpdate)

--Allows the player to request a save
function Player_Request_Save( player, command, args )
	Save_Player_Data( player )
end

concommand.Add( "db_save_info", Player_Request_Save )

--This sends the loaded stuff to the client
function UpdateUserCrap( player, command, args )
	umsg.Start( "SendStats", player )
		umsg.String( player.PrefCombModel )
		umsg.String( player.PrefLambModel )
	umsg.End( )
end

concommand.Add( "db_get_info", UpdateUserCrap )



/*Other console commands*/

--Randomly chooses a team.
function AutoTeam( pl )
	pl:KillSilent( )
	local tm = math.random(1,2)
	--You can not join in the middle of a round, so you will be set out for the remainder of that round.
	if ( Round_Active( ) == true ) then
		pl:PrintMessage( HUD_PRINTTALK, "You will remain out for the remainder of this round." )
		if ( tm == 1 ) then
			pl:SetTeam( TEAM_DEADCOMB )
		else
			pl:SetTeam( TEAM_DEADLAMB )
		end
	else
		if ( tm == 1 ) then
			pl:SetTeam( TEAM_COMBINE )
		else
			pl:SetTeam( TEAM_LAMBDA )
		end
	end
end

concommand.Add( "autoteam", AutoTeam )

--Sets the player's team to combine
function Join_Combine( pl )
	pl:KillSilent( )
	if ( Round_Active( ) == true ) then
		pl:PrintMessage( HUD_PRINTTALK, "You will remain out for the remainder of this round." )
		pl:SetTeam( TEAM_DEADCOMB )
	else
		pl:SetTeam( TEAM_COMBINE )
	end
end

concommand.Add( "join_combine", Join_Combine )

--Sets the player's team to lambda
function Join_Lambda( pl )
	pl:KillSilent( )
	if ( Round_Active( ) == true ) then
		pl:PrintMessage( HUD_PRINTTALK, "You will remain out for the remainder of this round." )
		pl:SetTeam( TEAM_DEADLAMB )
	else
		pl:SetTeam( TEAM_LAMBDA )
	end
end

concommand.Add( "join_lambda", Join_Lambda )